<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Behavior;
// 创建Lite运行文件
// 可以替换框架入口文件运行
// 建议绑定位置app_init
class QueueBehavior {
    public function run()
    {
    	// 处理队列配置
        $config = C('QUEUE');
        if ($config) {
            vendor('php-resque.autoload');
            // 初始化队列服务
            $select = isset($config['select']) ? $config['select'] : 0;
            $password = isset($config['password']) ? $config['password'] : null;
            $persistent = isset($config['persistent']) ? $config['persistent'] : false;
            $timeout = isset($config['timeout']) ? $config['timeout'] : 30;
            $server = $config['host'] . ":" . $config['port'];
            \Resque::setBackend($server, $select, $password, $persistent, $timeout);
            // 初始化缓存前缀
            if(isset($config['prefix']) && !empty($config['prefix'])){
                \Resque\Redis::prefix($config['prefix']);
            }
        }
    }
}
